﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace grid
{
    /// <summary>
    /// Node of the Lattice
    /// </summary>
    class LatticeNode
    {
        protected HashSet<string> _Intent;
        protected HashSet<string> _Extent;
        protected List<LatticeNode> _Parents;
        protected List<LatticeNode> _Children;

        public HashSet<string> Intent { get { return _Intent; } }
        public HashSet<string> Extent { get { return _Extent; } }

        public List<LatticeNode> Parents { get { return _Parents; } }
        public List<LatticeNode> Children { get { return _Children; } }

        /// <summary>
        /// Adds parent
        /// </summary>
        /// <param name="lnParent"></param>
        public void AddParent(LatticeNode lnParent)
        {
            if (_Parents == null)
                _Parents = new List<LatticeNode>();
            _Parents.Add(lnParent);
        }

        /// <summary>
        /// Adds child
        /// </summary>
        /// <param name="lnChild"></param>
        public void AddChild(LatticeNode lnChild)
        {
            if (_Children == null)
                _Children = new List<LatticeNode>();
            _Children.Add(lnChild);
        }

        /// <summary>
        /// Default constructor
        /// </summary>
        public LatticeNode()
        {
            _Extent = new HashSet<string>();
            _Intent = new HashSet<string>();
            _Parents = new List<LatticeNode>();
            _Children = new List<LatticeNode>();
        }

        /// <summary>
        /// Constructor, converts old LatticeNode to new
        /// </summary>
        /// <param name="old_ln"></param>
        public LatticeNode(Fca.DataStructures.LatticeNode old_ln,
            Fca.DataStructures.FormalContext old_cxt) : this()
        {
            Fca.DataStructures.SetArray sa = old_ln.Extent;
            for (int i = 0; i < sa.Capacity; i++)
            {
                if (sa[i])
                {
                    _Extent.Add(old_cxt.ObjectNames[i]);
                }
            }

            sa = old_ln.Intent;
            for (int i = 0; i < sa.Capacity; i++)
            {
                if (sa[i])
                {
                    _Intent.Add(old_cxt.AttributeNames[i]);
                }
            }
        }
    }
}
